package com.ruoyi.erp.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.erp.domain.DingtalkProcess;
import com.ruoyi.erp.service.IDingtalkProcessService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 请假加班Controller
 * 
 * @author sauger
 * @date 2022-04-18
 */
@Controller
@RequestMapping("/dingtalk/dingtalkProcess")
public class DingtalkProcessController extends BaseController
{
    private String prefix = "dingtalk/dingtalkProcess";

    @Autowired
    private IDingtalkProcessService dingtalkProcessService;

    @RequiresPermissions("dingtalk:dingtalkProcess:view")
    @GetMapping()
    public String dingtalkProcess()
    {
        return prefix + "/dingtalkProcess";
    }

    /**
     * 查询请假加班列表
     */
    @RequiresPermissions("dingtalk:dingtalkProcess:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DingtalkProcess dingtalkProcess)
    {
        startPage();
        List<DingtalkProcess> list = dingtalkProcessService.selectDingtalkProcessList(dingtalkProcess);
        return getDataTable(list);
    }

    /**
     * 导出请假加班列表
     */
    @RequiresPermissions("dingtalk:dingtalkProcess:export")
    @Log(title = "请假加班", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DingtalkProcess dingtalkProcess)
    {
        List<DingtalkProcess> list = dingtalkProcessService.selectDingtalkProcessList(dingtalkProcess);
        ExcelUtil<DingtalkProcess> util = new ExcelUtil<DingtalkProcess>(DingtalkProcess.class);
        return util.exportExcel(list, "请假加班数据");
    }

    /**
     * 新增请假加班
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存请假加班
     */
    @RequiresPermissions("dingtalk:dingtalkProcess:add")
    @Log(title = "请假加班", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DingtalkProcess dingtalkProcess)
    {
        return toAjax(dingtalkProcessService.insertDingtalkProcess(dingtalkProcess));
    }

    /**
     * 修改请假加班
     */
    @RequiresPermissions("dingtalk:dingtalkProcess:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        DingtalkProcess dingtalkProcess = dingtalkProcessService.selectDingtalkProcessById(id);
        mmap.put("dingtalkProcess", dingtalkProcess);
        return prefix + "/edit";
    }

    /**
     * 修改保存请假加班
     */
    @RequiresPermissions("dingtalk:dingtalkProcess:edit")
    @Log(title = "请假加班", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DingtalkProcess dingtalkProcess)
    {
        return toAjax(dingtalkProcessService.updateDingtalkProcess(dingtalkProcess));
    }

    /**
     * 删除请假加班
     */
    @RequiresPermissions("dingtalk:dingtalkProcess:remove")
    @Log(title = "请假加班", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dingtalkProcessService.deleteDingtalkProcessByIds(ids));
    }
}
